OB.Emes_ActionButton = OB.Emes_ActionButton || {};

//员工管理批量修改数据
OB.Emes_ActionButton.Emesployeeupdate   = function(d, b) {
	var e = b.activeView.viewGrid;
	var a = e.getSelectedRecords();
	var c = a.getLength();
	if (c) {
		// 选择纪录行
		var selectRecords = [];
		for (var i = 0; i < c; i++) {
			selectRecords.push(a[i].id);
			a.hz_id
		}
		OB.Emes_ActionButton.MyRefresh=function(){
			b.refresh();
		}
		OB.RemoteCallManager
				.call(													      
						"com.mes.handler.EmesployeeHandler",
						{
							ids : selectRecords.join("#####")
						},
						{},
						function(rpcResponse, data, rpcRequest) {
							if (!data.result) {
								alert(data.msg);
								return;
							}
							refershView = b;
							isc.OBEXAPP_Emesployeeupdate.create(data).show();
						});
	} else {
		isc.showMessage("请选择下发记录！");
	}
};

isc.defineClass('OBEXAPP_Emesployeeupdate',isc.OBPopup);

isc.OBEXAPP_Emesployeeupdate.addProperties({

	width : "70%",
	height : "70%",
	title : null,
	showMinimizeButton : false,
	showMaximizeButton : false,

	callPutData : null,
	callPutForm : null,
	okButton : null, 
	cancelButton : null,

	initWidget : function(data) {
		var reqData = data.reqData;
		var LocatorMap = data.LocatorMap;
		
		
		this.callPutForm = isc.ListGrid.create({
			ID : "callPutMaterialForm",
			canEdit : true,
			editByCell : true,
			editEvent : "click",
			data : reqData,
			width : "100%",
			height : 360,
			alternateRecordStyles : true,
			fields : [{
				width : "*",
				type : 'text',
				readOnlyDisplay : "static",
				canEdit : false,
				startRow : true,
				title : '员工ID',
				name : 'IDS'
			},{
				width : "15%",
				type : 'text',
				readOnlyDisplay : "static",
				canEdit : false,
				startRow : true,
				title : '员工姓名',
				name : 'NAMES'
			},{   
				width: '10%',type: 'select',title:'厂区',	  name: 'ORGNAME',	 valueMap: {sc: '四厂', wc: '五厂'} , readOnlyDisplay:"static",startRow:true
			}/*, {
				width : "10%",
				type : 'text',
				readOnlyDisplay : "static",
				canEdit : true,
				startRow : false,
				title : '厂区',
				name : 'ORGNAME'
			}*/, {
				width : "15%",
				type : 'text',
				readOnlyDisplay : "static",
				canEdit : true,
				startRow : false,
				title : '部门',
				name : 'BMNAME'
			}, {
				width : "15%",
				type : 'text',
				readOnlyDisplay : "static",
				canEdit : true,
				startRow : true,
				title : '工序',
				name : 'GROUPNAME'
			},{
				width : "15W%",
				type : 'text',
				readOnlyDisplay : "static",
				canEdit : true,
				startRow : true,
				title : '岗位',
				name : 'GWNAME'
			},{   
				width: '10%',type: 'select',title:'员工状态',	  name: 'STATUS',	 valueMap: {work: '在职', Quit: '离职'} , readOnlyDisplay:"static",startRow:true
			} ,{
				width : "20%",
				type : 'date',
				readOnlyDisplay : "static",
				canEdit : true,
				startRow : true,
				title : '离职时间',
				name : 'LEAVETIME'
			},{
				width : "15%",
				type : 'text',
				readOnlyDisplay : "static",
				canEdit : true,
				startRow : true,
				title : '调动原职务',
				name : 'OLDNAME'
			}]
		});
		// 隐藏ids
		callPutMaterialForm.hideField('IDS');
		// OK Button
		this.okButton = isc.OBFormButton.create({
					title : '确定',
					popup : this,
					action : function() {callPutMaterialForm.saveEdits();
						var flag = true;
						var upResult = callPutMaterialForm.data;
						var cL = upResult.length;
						
						for (var i = 0; i < cL; i++) {
							var ORGNAMES = upResult[i].ORGNAME;
							var BMNAMES = upResult[i].BMNAME;
							var GROUPNAMES = upResult[i].GROUPNAME;
							var GWNAMES = upResult[i].GWNAME;
							var STATUSS = upResult[i].STATUS;
							var LEAVETIMES = upResult[i].LEAVETIME;
							var OLDNAMES = upResult[i].OLDNAME;
							
							
							if(!ORGNAMES){
								isc.showMessage("第"+(i+1)+"行厂区不能为空！");
								//this.popup.closeClick();
								return ;
							}else{
								if(!BMNAMES){
									isc.showMessage("第"+(i+1)+"行部门不能为空！");
									//this.popup.closeClick();
									return ;
								}else{
									if(!GROUPNAMES){
										isc.showMessage("第"+(i+1)+"行班组不能为空！");
										//this.popup.closeClick();
										return ;
									}else{
										if(!GWNAMES){
											isc.showMessage("第"+(i+1)+"行岗位不能为空！");
											///this.popup.closeClick();
											return ;
										}else{
											if(STATUSS== 'work'){
													
											}else if(STATUSS== 'Quit'){
													
											}else if(!STATUSS){
												isc.showMessage("第"+(i+1)+"行状态不能为空！");
												//this.popup.closeClick();
													return ;
											}
										}
									}
								}
							}
						}	
							
						var callback = function(
								rpcResponse,
								data,
								rpcRequest) {
							if (data.message.severity == "success") {
								refershView.refresh();
								isc.showMessage(data.message.text,isc.OBMessageBar.TYPE_INFO);
								rpcRequest.clientContext.popup.closeClick();
							} else {
								isc.showMessage(data.message,isc.OBMessageBar.TYPE_INFO);
							}
							OB.Emes_ActionButton.MyRefresh();

						};
						OB.RemoteCallManager.call("com.mes.handler.EmesemployeeUpdateHandler",{dateParam : upResult}, {}, callback);
						//this.popup.closeClick();
					}
				});

		// Cancel Button
		this.cancelButton = isc.OBFormButton.create({
					title : '取消',
					popup : this,
					action : function() {
						this.popup.closeClick();
					}
				});

		//Add the elements into a layout   
		this.items = [ isc.VLayout.create({
			defaultLayoutAlign : "center",
			align : "center",
			width : "100%",
			layoutMargin : 15,
			membersMargin : 70,
			members : [
					isc.HLayout
							.create({
								defaultLayoutAlign : "center",
								align : "center",
								width : "100%",
								height : "80%",
								members : [ this.callPutForm ]
							}),
					isc.HLayout
							.create({
								defaultLayoutAlign : "center",
								align : "center",
								membersMargin : 10,
								marginBottom : 10,
								members : [
										this.okButton,
										this.cancelButton ]
							}) ]
		}) ];

		this.Super('initWidget',arguments);
	}

});
